// -----------------------------------------------
// Author:     code34 nicolas_boiteux@yahoo.fr
// Edited by:  Neumatic
// Warcontext: Create a building vehicles dialog box
// -----------------------------------------------

private [
	"_vehicles",
	"_name",
	"_index",
	"_position",
	"_type",
	"_textbox",
	"_array"
];

if !(name player in wcinteam) exitWith {
	wcgarbage = [localize "STR_WC_MENURECRUITMENT", "Only members of team can build", "Wait to be recruit as team member", 10] spawn WC_fnc_playerhint;
	closeDialog 0;
};

disableSerialization;
_textbox = (uiNamespace getVariable "wcdisplay") displayCtrl 7001;

switch (wcwithvehicles) do {
	case 1: {
		_vehicles = [];
	};

	case 2: {
		_vehicles = wcvehicleslistathq;
	};

	case 3: {
		_vehicles = wcvehicleslistW;
	};
};

_array = [];

{
	_name = getText (configFile >> "CfgVehicles" >> _x >> "DisplayName");
	_index = lbAdd [7002, _name];
	_array set [_index, _x];
} foreach _vehicles;

lbSetCurSel [7002, 0];

while {alive player && {dialog}} do {
	_index = lbCurSel 7002;
	_type = _array select _index;

	if (menuaction == 1) then {
		menuaction = -1;
		wcgarbage = ["Build a vehicle", "Wait while the building of your vehicle", "The vehicle will appear near you in few seconds. Older one will be delete.", 3] spawn WC_fnc_playerhint;
		_position = (getPosATL player) findEmptyPosition [5, 30];
		if (_position select 0 == 0) then {
			diag_log "WARCONTEXT: CANNOT FIND EMPTY POSITION FOR CREATE ATV";
		} else {
			deleteVehicle wcmyatv;
			closeDialog 0;
			sleep 3;
			wcmyatv = createVehicle [_type, _position, [], 0, "NONE"];
		};
	};

	if (menuaction == 2) then {
		menuaction = -1;
		closeDialog 0;
	};

	sleep 0.5;
};